<template>
  <div v-loading="loading">
    <a-form-model ref="ruleForm" :model="localForm" :rules="baseFormRules">
      <a-card>
        <title-name title="'基本信息" />
        <a-row v-if="type === null">
          <a-col span="24">
            <a-form-model-item label="合同名称" prop="contractName">
              <b-input v-model="localForm.contractName" placeholder="请输入" />
            </a-form-model-item>
          </a-col>
          <a-col span="16">
            <a-form-model-item label="所属单位" prop="projectId">
              <org-tree-select
                               v-model="localForm.projectId"
                               :isAutoSelectFirst="!isEdit"
                               checkStrictly
                               :disabled="disabled"
                               @select="selctOrg"></org-tree-select>
            </a-form-model-item>
          </a-col>
<!--           <a-col span="8">-->
<!--            <a-form-model-item-->
<!--              label="所属分公司"-->
<!--              prop="branchCompanyId"-->
<!--            >-->
<!--              <SelectSubCompany-->
<!--                v-model="localForm.branchCompanyId"-->
<!--                placeholder="请选择"-->
<!--                :disabled="disabled"-->
<!--              />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col span="8">-->
<!--            <a-form-model-item-->
<!--              label="项目名称"-->
<!--              prop="projectId"-->
<!--            >-->
<!--              <SelectProject-->
<!--                v-model="localForm.projectId"-->
<!--                :disabled="disabled"-->
<!--                placeholder="请选择"-->
<!--                :form="localForm"-->
<!--                :is-clear="false"-->
<!--                :is-edit="true"-->
<!--                key-value="branchCompanyId"-->
<!--              />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col span="8">
            <a-form-model-item label="建设单位名称" prop="otherParty">
              <b-input v-model="localForm.otherParty" placeholder="请输入" :max-length="50" />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="建设单位性质" prop="buildTypeId">
              <BSelect v-model="localForm.buildTypeId" :request="() => getTypeLabel(29)" />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="中标时间" prop="bidDate">
              <a-date-picker type="date" v-model="localForm.bidDate" :disabledDate="disabledDate" valueFormat="YYYY-MM-DD" />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="签约时间" prop="signDate">
              <a-date-picker type="date" v-model="localForm.signDate" :disabledDate="disabledDate2" valueFormat="YYYY-MM-DD" />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="合同类型" prop="contractTypeId">
              <a-select v-model="localForm.contractTypeId" placeholder="请选择">
                <a-select-option v-for="item in selectOptionList.contract" :key="item.id" :value="item.id">
                  {{ item.name }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="合同额（万元）" prop="amount">
              <b-input-number v-model="localForm.amount" :min="0" :precision="2" placeholder="请输入" />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="合同份数" prop="contractNum">
              <b-input-number v-model="localForm.contractNum" placeholder="请输入" is-int :min="0" />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="项目经理" prop="pmEmployeeName">
              <a-input-search v-model="localForm.pmEmployeeName" placeholder="请选择" @click="$refs.personList.open()" @search="$refs.personList.open()" />
            </a-form-model-item>
          </a-col>

          <a-col span="8">
            <a-form-model-item label="联系电话">
              <b-input v-model="localForm.pmEmployeePhone" placeholder="请选择项目经理" disabled type="number" />
            </a-form-model-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-model-item label="是否有重大风险" prop="majorRisk">
              <a-select v-model="localForm.majorRisk" placeholder="请选择">
                <a-select-option :value="1"> 是 </a-select-option>
                <a-select-option :value="0"> 否 </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="项目业态" prop="projectFormat">
              <a-select v-model="localForm.projectFormat" placeholder="请选择">
                <a-select-option v-for="item in selectOptionList.projectFormats" :key="item.id" :value="item.id">
                  {{ item.name }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="项目类型" prop="projectType">
              <a-select v-model="localForm.projectType" placeholder="请选择">
                <a-select-option v-for="item in selectOptionList.projectTypes" :key="item.id" :value="item.id">
                  {{ item.name }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="预付款金额（万元）" prop="advanceAmount">
              <b-input-number v-model="localForm.advanceAmount" placeholder="请输入" :min="0" :precision="2" />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="付款方式" prop="payTypeId">
              <BSelect v-model="localForm.payTypeId" :request="() => getTypeLabel(27)" />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="付款比例（%）" prop="paymentProportion">
              <b-input-number v-model="localForm.paymentProportion" placeholder="请输入" :min="0" :precision="2" :max="100" />
            </a-form-model-item>
          </a-col>

          <a-col span="8">
            <a-form-model-item label="结算条件" prop="settleCnditions">
              <a-select v-model="localForm.settleCnditions" placeholder="请选择">
                <a-select-option v-for="item in selectOptionList.settleCnditionss" :key="item.id" :value="item.id">
                  {{ item.name }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="施工范围" prop="scopeTypeId">
              <BSelect v-model="localForm.scopeTypeId" :request="() => getTypeLabel(28)" />
            </a-form-model-item>
          </a-col>
          <a-col span="24">
            <a-form-model-item label="特别说明" prop="specialInstructions">
              <b-textarea v-model="localForm.specialInstructions" placeholder="请输入" :auto-size="{ minRows: 2, maxRows: 6 }" :max-length="1000" />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="创建人">
              <b-input v-model="localForm.creatorName" disabled />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="创建时间">
              <b-input :value="localForm.createTime" disabled />
            </a-form-model-item>
          </a-col>
        </a-row>

        <template v-else>
          <a-descriptions>
            <a-descriptions-item label="合同名称">
              {{ localForm.contractName }}
            </a-descriptions-item>
          </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="所属单位">
              {{ (localForm.branchComName + '/' + localForm.projectName) | ellipsis }}
            </a-descriptions-item>
            <!-- <a-descriptions-item label="所属分公司">
              {{ localForm.branchComName }}
            </a-descriptions-item>
            <a-descriptions-item label="项目名称">
              {{ localForm.projectName }}
            </a-descriptions-item> -->
            <a-descriptions-item label="建设单位名称">
              {{ localForm.otherParty }}
            </a-descriptions-item>
          </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="建设单位性质">
              {{ localForm.buildTypeStr }}
            </a-descriptions-item>
            <a-descriptions-item label="中标时间">
              {{ localForm.bidDate }}
            </a-descriptions-item>
            <a-descriptions-item label="签约时间">
              {{ localForm.signDate }}
            </a-descriptions-item>
          </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="合同类型">
              {{ localForm.contractTypeStr }}
            </a-descriptions-item>
            <a-descriptions-item label="合同额（万元）">
              {{ localForm.amount }}
            </a-descriptions-item>
          </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="合同份数">
              {{ localForm.contractNum }}
            </a-descriptions-item>
            <a-descriptions-item label="项目经理">
              {{ localForm.pmEmployeeName }}
            </a-descriptions-item>
            <a-descriptions-item label="联系电话">
              {{ localForm.pmEmployeePhone }}
            </a-descriptions-item>
          </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="是否有重大风险">
              {{ localForm.majorRisk == 1 ? '是' : '否' }}
            </a-descriptions-item>
            <a-descriptions-item label="项目业态">
              {{ localForm.projectFormatStr }}
            </a-descriptions-item>
            <a-descriptions-item label="项目类型">
              {{ localForm.projectType }}
            </a-descriptions-item>
          </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="预付款金额（万元）">
              {{ localForm.advanceAmount }}
            </a-descriptions-item>
            <a-descriptions-item label="付款比例（%）">
              {{ localForm.paymentProportion }}
            </a-descriptions-item>
            <a-descriptions-item label="结算条件">
              {{ localForm.settleCnditionsStr }}
            </a-descriptions-item>
          </a-descriptions>

          <a-descriptions>
            <a-descriptions-item label="特别说明">
              {{ localForm.specialInstructions }}
            </a-descriptions-item>
          </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="创建人">
              {{ localForm.creatorName }}
            </a-descriptions-item>
            <a-descriptions-item label="创建时间">
              {{ localForm.createTime }}
            </a-descriptions-item>
          </a-descriptions>
        </template>
      </a-card>
      <a-card>
        <title-name title="分公司评审人员" />
        <a-row v-if="type === null">
          <a-col span="8">
            <a-form-model-item label="市场部/基础设施部" prop="bcMarkeDept">
              <SelectUndertaking
                :init="false"
                v-model="localForm.bcMarkeDeptObj"
                placeholder="请选择"
                :request-params="{ and: true, orgType: '2' }"
                :org-id="localForm.branchCompanyId"
                :is-default="false"
                :is-include="true"
                @change=";(localForm.bcMarkeDept = localForm.bcMarkeDeptObj.key), (localForm.bcMarkeDeptName = localForm.bcMarkeDeptObj.label)"
              />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="工程管理部" prop="bcEngineeDept">
              <SelectUndertaking
                :init="false"
                v-model="localForm.bcEngineeDeptObj"
                :org-id="localForm.branchCompanyId"
                :is-default="false"
                :is-include="true"
                :request-params="{ and: true, orgType: '2' }"
                placeholder="请选择"
                @change=";(localForm.bcEngineeDept = localForm.bcEngineeDeptObj.key), (localForm.bcEngineeDeptName = localForm.bcEngineeDeptObj.label)"
              />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="财务资金部" prop="bcFinanceDept">
              <SelectUndertaking
                :init="false"
                v-model="localForm.bcFinanceDeptObj"
                :org-id="localForm.branchCompanyId"
                :is-default="false"
                :is-include="true"
                :request-params="{ and: true, orgType: '2' }"
                placeholder="请选择"
                @change=";(localForm.bcFinanceDept = localForm.bcFinanceDeptObj.key), (localForm.bcFinanceDeptName = localForm.bcFinanceDeptObj.label)"
              />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="合约法务部" prop="bcLegalDept">
              <SelectUndertaking
                :init="false"
                v-model="localForm.bcLegalDeptObj"
                :org-id="localForm.branchCompanyId"
                :is-default="false"
                :is-include="true"
                :request-params="{ and: true, orgType: '2' }"
                placeholder="请选择"
                @change=";(localForm.bcLegalDept = localForm.bcLegalDeptObj.key), (localForm.bcLegalDeptName = localForm.bcLegalDeptObj.label)"
              />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="商务管理部" prop="bcMinistryDept">
              <SelectUndertaking
                :init="false"
                v-model="localForm.bcMinistryDeptObj"
                :org-id="localForm.branchCompanyId"
                :is-default="false"
                :is-include="true"
                :request-params="{ and: true, orgType: '2' }"
                placeholder="请选择"
                @change=";(localForm.bcMinistryDept = localForm.bcMinistryDeptObj.key), (localForm.bcMinistryDeptName = localForm.bcMinistryDeptObj.label)"
              />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="科技部" prop="bcTechnologyDept">
              <SelectUndertaking
                :init="false"
                v-model="localForm.bcTechnologyDeptObj"
                :org-id="localForm.branchCompanyId"
                :is-default="false"
                :is-include="true"
                :request-params="{ and: true, orgType: '2' }"
                placeholder="请选择"
                @change=";(localForm.bcTechnologyDept = localForm.bcTechnologyDeptObj.key), (localForm.bcTechnologyDeptName = localForm.bcTechnologyDeptObj.label)"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <div v-else>
          <a-descriptions>
            <a-descriptions-item label="市场部/基础设施部">
              {{ localForm.bcMarkeDeptName }}
            </a-descriptions-item>
            <a-descriptions-item label="工程管理部">
              {{ localForm.bcEngineeDeptName }}
            </a-descriptions-item>
            <a-descriptions-item label="财务资金部">
              {{ localForm.bcFinanceDeptName }}
            </a-descriptions-item>
          </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="合约法务部">
              {{ localForm.bcLegalDeptName }}
            </a-descriptions-item>
            <a-descriptions-item label="商务管理部">
              {{ localForm.bcMinistryDeptName }}
            </a-descriptions-item>
            <a-descriptions-item label="科技部">
              {{ localForm.bcTechnologyDeptName }}
            </a-descriptions-item>
          </a-descriptions>
        </div>
      </a-card>
      <a-card>
        <title-name title="公司评审人员" />
        <a-row v-if="type === null">
          <a-col span="8">
            <a-form-model-item label="市场部/基础设施部" prop="coMarkeDept">
              <SelectUndertaking
                v-model="localForm.coMarkeDeptObj"
                :is-default="false"
                :is-include="true"
                :request-params="{ and: true, orgType: '2' }"
                org-id="53085e2c9f1f4685801ef31994f57c49"
                placeholder="请选择"
                @change=";(localForm.coMarkeDept = localForm.coMarkeDeptObj.key), (localForm.coMarkeDeptName = localForm.coMarkeDeptObj.label)"
              />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="工程管理部" prop="coEngineeDept">
              <SelectUndertaking
                v-model="localForm.coEngineeDeptObj"
                :is-default="false"
                :is-include="true"
                :request-params="{ and: true, orgType: '2' }"
                org-id="53085e2c9f1f4685801ef31994f57c49"
                placeholder="请选择"
                @change=";(localForm.coEngineeDept = localForm.coEngineeDeptObj.key), (localForm.coEngineeDeptName = localForm.coEngineeDeptObj.label)"
              />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="财务资金部" prop="coFinanceDept">
              <SelectUndertaking
                v-model="localForm.coFinanceDeptObj"
                :is-default="false"
                :is-include="true"
                :request-params="{ and: true, orgType: '2' }"
                org-id="53085e2c9f1f4685801ef31994f57c49"
                placeholder="请选择"
                @change=";(localForm.coFinanceDept = localForm.coFinanceDeptObj.key), (localForm.coFinanceDeptName = localForm.coFinanceDeptObj.label)"
              />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="合约法务部" prop="coLegalDept">
              <SelectUndertaking
                v-model="localForm.coLegalDeptObj"
                :is-default="false"
                :is-include="true"
                :request-params="{ and: true, orgType: '2' }"
                org-id="53085e2c9f1f4685801ef31994f57c49"
                placeholder="请选择"
                @change=";(localForm.coLegalDept = localForm.coLegalDeptObj.key), (localForm.coLegalDeptName = localForm.coLegalDeptObj.label)"
              />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="商务管理部" prop="coMinistryDept">
              <SelectUndertaking
                v-model="localForm.coMinistryDeptObj"
                :is-default="false"
                :is-include="true"
                :request-params="{ and: true, orgType: '2' }"
                org-id="53085e2c9f1f4685801ef31994f57c49"
                placeholder="请选择"
                @change=";(localForm.coMinistryDept = localForm.coMinistryDeptObj.key), (localForm.coMinistryDeptName = localForm.coMinistryDeptObj.label)"
              />
            </a-form-model-item>
          </a-col>
          <a-col span="8">
            <a-form-model-item label="科技部" prop="coTechnologyDept">
              <SelectUndertaking
                v-model="localForm.coTechnologyDeptObj"
                :is-default="false"
                :is-include="true"
                :request-params="{ and: true, orgType: '2' }"
                org-id="53085e2c9f1f4685801ef31994f57c49"
                placeholder="请选择"
                @change=";(localForm.coTechnologyDept = localForm.coTechnologyDeptObj.key), (localForm.coTechnologyDeptName = localForm.coTechnologyDeptObj.label)"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <div v-else>
          <a-descriptions>
            <a-descriptions-item label="市场部/基础设施部">
              {{ localForm.coMarkeDeptName }}
            </a-descriptions-item>
            <a-descriptions-item label="工程管理部">
              {{ localForm.coEngineeDeptName }}
            </a-descriptions-item>
            <a-descriptions-item label="财务资金部">
              {{ localForm.coFinanceDeptName }}
            </a-descriptions-item>
          </a-descriptions>
          <a-descriptions>
            <a-descriptions-item label="合约法务部">
              {{ localForm.coLegalDeptName }}
            </a-descriptions-item>
            <a-descriptions-item label="商务管理部">
              {{ localForm.coMinistryDeptName }}
            </a-descriptions-item>
            <a-descriptions-item label="科技部">
              {{ localForm.coTechnologyDeptName }}
            </a-descriptions-item>
          </a-descriptions>
        </div>
      </a-card>
      <attachment :attachment="localForm.fileInfos" :disabled="type === null" @change="(e) => (localForm.fileInfos = e)" />
    </a-form-model>
    <div class="page-btn-right-top">
      <!-- <div
      class="operation"
      style="text-align: right; margin-right: 20px"
    > -->
      <template v-if="isShowOptions()">
        <a-button v-if="localForm.branchComReview == 'REJECTED'" type="primary" :loading="saveLoading" class="mr10p" @click="save(localForm.branchComReview)"> 保存 </a-button>
        <a-button v-else type="primary" :loading="saveLoading" class="mr10p" @click="save()"> 保存草稿 </a-button>
        <a-button type="primary" :loading="submitLoading" class="mr10p" @click="submit"> 提交 </a-button>
      </template>
      <a-button @click="$close"> 关闭 </a-button>
    </div>
    <person-list ref="personList" @getPerson="getPerson" />
    <supplier-list ref="supplierList" @createList="getSupplier" />

    <a-modal :visible="selectJobsVisible" class="normal-modal" :confirm-loading="loading" @ok="baseChangeSubmit" @cancel="baseChangeCancel">
      <title-name title="选择岗位" />
      <a-row>
        <a-col :span="12">
          <a-form-model-item class="flex" label="组织" prop="orgSelectedName">
            <TreeSelectOrganization
              v-model="form.orgSelectedName"
              :org-selected-value.sync="form.orgSelectedName"
              :org-selected-label.sync="form.orgSelectedLabel"
              :org-query="{ pid: orgId, cascade: true }"
              children-node="jobs"
            />
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item class="flex" label="岗位" prop="jobsSelectedName">
            <Jobs v-model="form.jobsSelectedName" :selected-value.sync="form.jobsSelectedName" :tree-checkable="true" :add-titel="form.orgSelectedLabel[0]" />
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-modal>
  </div>
</template>

<script>
import totalPackageContractApi from '@/api/legal/branchContract/totalPackageContract'
import { getInfoByStaffId } from '@/api/commons'
import SelectSubCompany from '@/components/Select/SelectSubCompany'
import SelectProject from '@/components/Select/SelectProject'
import SupplierList from '@/components/supplierList/supplierList'
import { getPostManageList, getPostManageList2 } from '@/api/system/system'
import TreeSelectOrganization from '@/components/TreeSelectOrganization'
import Jobs from '@/components/TreeSelectOrganization/jobs'
import SelectUndertaking from '@/components/Select/SelectUndertaking'
import attachment from './attachment'
import moment from 'moment'
export default {
  name: 'a' + Date.now(),
  components: {
    SelectSubCompany,
    SelectProject,
    SupplierList,
    TreeSelectOrganization,
    SelectUndertaking,
    Jobs,
    attachment
  },
  props: {
    baseForm: {
      type: Object
    },
    type: {
      type: Number,
      default() {
        return 1
      }
    },
    selectOptionList: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  watch:{
    type: {
      handler(val, oldVal) {
        if (val) {
          console.log('valvalvalvalval',val)
        }
      },
      immediate: true
    }
  },
  data() {
    return {
      getTypeLabel: (type) => totalPackageContractApi.typeslabel({ pageNo: 0, pageSize: 100000, query: { type } }),
      loading: false,
      submitLoading: false,
      saveLoading: false,
      localForm: {
        branchCompanyId: '',
        projectId: '',
        otherParty: '',
        pmEmployeeName: '',
        bidDate: '',
        pmEmployeePhone: '',
        fileInfos: []
      },
      baseFormRules: {
        scopeTypeId: { required: true, message: '请选择施工范围', trigger: 'change' },
        bidDate: { required: true, message: '请选择中标时间', trigger: 'change' },
        signDate: { required: true, message: '请选择签约时间', trigger: 'change' },
        payTypeId: { required: true, message: '请选择付款方式', trigger: 'change' },
        buildTypeId: { required: true, message: '请选择建设单位性质', trigger: 'change' },
        contractName: { required: true, message: '请输入合同名称', trigger: 'blur' },
        branchCompanyId: { required: true, message: '请选择所属分公司', trigger: 'change' },
        projectId: { required: true, message: '请选择项目名称', trigger: 'change' },
        otherParty: { required: true, message: '请输入建设单位名称', trigger: 'blur' },
        contractTypeId: { required: true, message: '请选择合同类型', trigger: 'change' },
        amount: { required: true, message: '请输入合同额（万元）', trigger: 'blur' },
        contractNum: { required: true, message: '请输入合同份数', trigger: 'blur' },
        pmEmployeeName: { required: true, message: '请选择项目经理', trigger: 'change' },
        phone: { required: true, message: '请输入联系电话', trigger: 'blur' },
        specialInstructions: { required: true, message: '请输入特别说明', trigger: 'blur' },
        majorRisk: { required: true, message: '请选择', trigger: 'blur' },
        projectFormat: { required: true, message: '请选择', trigger: 'blur' },
        advanceAmount: { required: true, message: '请选择', trigger: 'blur' },
        projectType: { required: true, message: '请输入', trigger: 'blur' },
        paymentProportion: { required: true, message: '请输入', trigger: 'blur' },
        settleCnditions: { required: true, message: '请选择', trigger: 'blur' },
        bcMarkeDept: { required: true, message: '请选择', trigger: 'blur' },
        bcEngineeDept: { required: true, message: '请选择', trigger: 'blur' },
        bcFinanceDept: { required: true, message: '请选择', trigger: 'blur' },
        bcLegalDept: { required: true, message: '请选择', trigger: 'blur' },
        bcMinistryDept: { required: true, message: '请选择', trigger: 'blur' },
        bcTechnologyDept: { required: true, message: '请选择', trigger: 'blur' },
        coMarkeDept: { required: true, message: '请选择', trigger: 'blur' },
        coEngineeDept: { required: true, message: '请选择', trigger: 'blur' },
        coFinanceDept: { required: true, message: '请选择', trigger: 'blur' },
        coLegalDept: { required: true, message: '请选择', trigger: 'blur' },
        coMinistryDept: { required: true, message: '请选择', trigger: 'blur' },
        coTechnologyDept: { required: true, message: '请选择', trigger: 'blur' }
      },
      form: {
        orgSelectedName: '',
        orgSelectedLabel: '',
        jobsSelectedName: undefined, //岗位
        respEmployeeId: undefined //人员
      },
      selectJobsVisible: false,
      orgId: '',
      isEdit: false
    }
  },
  watch: {
    baseForm: {
      deep: true,
      immediate: true,
      handler() {
        this.localForm = this.$assign(this.localForm, this.baseForm)

        this.$set(this.localForm, 'bcMarkeDeptObj', {
          key: this.localForm.bcMarkeDept,
          label: this.localForm.bcMarkeDeptName
        })
        this.$set(this.localForm, 'bcEngineeDeptObj', {
          key: this.localForm.bcEngineeDept,
          label: this.localForm.bcEngineeDeptName
        })
        this.$set(this.localForm, 'bcFinanceDeptObj', {
          key: this.localForm.bcFinanceDept,
          label: this.localForm.bcFinanceDeptName
        })
        this.$set(this.localForm, 'bcLegalDeptObj', {
          key: this.localForm.bcLegalDept,
          label: this.localForm.bcLegalDeptName
        })
        this.$set(this.localForm, 'bcMinistryDeptObj', {
          key: this.localForm.bcMinistryDept,
          label: this.localForm.bcMinistryDeptName
        })
        this.$set(this.localForm, 'bcTechnologyDeptObj', {
          key: this.localForm.bcTechnologyDept,
          label: this.localForm.bcTechnologyDeptName
        })
        this.$set(this.localForm, 'coMarkeDeptObj', {
          key: this.localForm.coMarkeDept,
          label: this.localForm.coMarkeDeptName
        })
        this.$set(this.localForm, 'coEngineeDeptObj', {
          key: this.localForm.coEngineeDept,
          label: this.localForm.coEngineeDeptName
        })
        this.$set(this.localForm, 'coFinanceDeptObj', {
          key: this.localForm.coFinanceDept,
          label: this.localForm.coFinanceDeptName
        })
        this.$set(this.localForm, 'coLegalDeptObj', {
          key: this.localForm.coLegalDept,
          label: this.localForm.coLegalDeptName
        })
        this.$set(this.localForm, 'coMinistryDeptObj', {
          key: this.localForm.coMinistryDept,
          label: this.localForm.coMinistryDeptName
        })
        this.$set(this.localForm, 'coTechnologyDeptObj', {
          key: this.localForm.coTechnologyDept,
          label: this.localForm.coTechnologyDeptName
        })
      }
    }
  },
  created() {
    let { name } = this.$userInfo().employee
    this.localForm.creatorName = name
    // this.localForm.createTime = Date.now()
    if(this.$route.query.state == 1) {
      this.isEdit = false
    } else {
      this.isEdit = true
    }
    this.localForm.createTime = this.$dateFormat(new Date(), 'D')
    console.log('this.localForm.createTime',this.localForm.createTime)
  },
  computed: {
    disabled() {
      return this.localForm.branchComReview && this.localForm.branchComReview === 'PAST'
    }
  },
  methods: {
    selctOrg(val) {
      if(this.localForm.branchCompanyId === val[val.length - 2].orgId) {
        return
      }
      this.$set(this.localForm, 'bcMarkeDeptObj', {
        key: "",
        label: ""
      })
      this.$set(this.localForm, 'bcEngineeDeptObj', {
        key: "",
        label: ""
      })
      this.$set(this.localForm, 'bcFinanceDeptObj', {
        key: "",
        label: ""
      })
      this.$set(this.localForm, 'bcLegalDeptObj', {
        key: "",
        label: ""
      })
      this.$set(this.localForm, 'bcMinistryDeptObj', {
        key: "",
        label: ""
      })
      this.$set(this.localForm, 'bcTechnologyDeptObj', {
        key: "",
        label: ""
      })
      this.localForm.branchCompanyId = val[val.length - 2].orgId

    },
    disabledDate(current) {
      return current && current > moment()
    },
    disabledDate2(current) {
      if (!this.localForm.bidDate) return true
      return current && (current > moment() || current < moment(this.localForm.bidDate))
    },
    getOption(e) {
      console.log(e)
    },
    isShowOptions() {
      if (this.type === null) {
        if (this.localForm.branchComReview === 'PAST') {
          return this.localForm.baseChangeStatus !== 'SUBMITTED'
        } else {
          return true
        }
      }
      return false
    },
    getSupplier(row) {
      this.localForm.otherParty = row.name
    },
    getPerson(row) {
      // this.$console(row)
      this.localForm.pmEmployeeName = row.name
      this.localForm.pmEmployeePhone = row.phoneNum
      this.localForm.pmEmployeeId = row.userId
    },
    baseChangeCancel() {
      this.form = {
        orgSelectedName: '',
        orgSelectedLabel: '',
        jobsSelectedName: undefined, //岗位
        respEmployeeId: undefined //人员
      }
      this.selectJobsVisible = false
    },
    async baseChangeSubmit() {
      const { jobsSelectedName } = this.form
      if (jobsSelectedName === undefined || jobsSelectedName.length === 0) {
        return this.$noticeWarning('请选择岗位')
      }
      this.loading = true
      let res = await totalPackageContractApi.generalSubmit({
        auditStatusEnum: 'SUBMITTED',
        baseId: this.baseForm.baseId,
        majorRisks: '0',
        submitCode: '1111',
        assgins: jobsSelectedName.join(',')
      })
      this.loading = false
      if (res.code === 200) {
        this.$noticeSuccess('提交成功')
        setTimeout(() => {
          this.$close()
          return Promise.resolve()
        }, this.TIMEOUT_DELAY)
      }
    },
    async submit() {
      this.save('SUBMITTED')
      // if (!(await this.save())) {
      //     return
      // }
      // if (this.localForm.branchComReview && this.localForm.branchComReview === 'PAST') {
      //     this.selectJobsVisible = true
      // } else {
      //     this.$bus.$emit('submit', '1102', '0')
      // }
    },
    isValidate() {
      let flag = true

      this.$refs.ruleForm.validate((valid, object) => {
        flag = valid
      })
      return flag
    },
    save(status = 'DRAFT') {
      return new Promise(async (resolve) => {
        if (status == 'SUBMITTED') {
          if (!this.isValidate()) return
        }
        if (status == 'SUBMITTED' && this.localForm.fileInfos.length == 0) {
          this.$noticeWarning('请上传附件!')
          return
        }
        this.loading = true
        status == 'DRAFT' ? (this.saveLoading = true) : (this.submitLoading = true)
        if (this.localForm.branchComReview && this.localForm.branchComReview === 'PAST') {
          this.localForm.baseChangeStatus = status
        } else {
          this.localForm.branchComReview = status
        }
        this.localForm.comAuditReview = status
        let res
        if (this.localForm.baseId) {
          res = await totalPackageContractApi.editByMain(this.localForm)
        } else {
          res = await totalPackageContractApi.createByMain(this.localForm)
        }

        if (res.code === 200) {
          this.localForm.baseId = res.data.baseId
          this.$emit('update', res.data.baseId)

          if (status === 'SUBMITTED') {
            this.$noticeSuccess('提交成功')
            this.$multiTab.close(this.$route.fullpath)
          } else {
            this.$noticeSuccess('保存成功')
          }
         this.$router.back()
          resolve(true)
        }
        this.loading = false
        status == 'DRAFT' ? (this.saveLoading = false) : (this.submitLoading = false)

        resolve(false)
      })
    }
  }
}
</script>

<style lang="less">
.ant-descriptions-item {
  white-space: nowrap;
}
</style>
